package com.sayp.netdisk.controller;

import com.sayp.netdisk.pojo.File;
import com.sayp.netdisk.pojo.User;
import com.sayp.netdisk.service.FileService;
import com.sayp.netdisk.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/file")
public class SearchController {
    @Autowired
    private UserController userController;
    //注入
    @Autowired
    private SearchService searchService;
    /**
     * 查询所有文件
     * @param parentId
     * @param cid
     * @param search
     * @return
     */
    @GetMapping("find/{parentId}/{cid}")
    public List<File> findFile(
            @PathVariable("parentId") int parentId,
            @PathVariable("cid") int cid,
            String search,
            HttpSession session){
        User user = userController.getUserInfo(session);
        //无法查询到用户信息
        if(user==null)return null;
        return searchService.findFile(parentId, cid, search, user.getUid());
    }
    /**
     * 查询符合要求文件
     * @param parentId
     * @param cid
     * @param search
     * @return
     */
    @GetMapping("find1/{parentId}/{cid}")
    public List<File> findFile1(
            @PathVariable("parentId") int parentId,
            @PathVariable("cid") int cid,
            String search,
            HttpSession session){
        User user = userController.getUserInfo(session);
        //无法查询到用户信息
        if(user==null)return null;
        return searchService.findFile1(parentId, cid, search, user.getUid());
    }

}
